<template>
  <div id="app" :style="{height:heihgt,width:width}">
    <router-view />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'app',
  data () {
    return {
      heihgt: '100vh',
      width: '100vw'
    }
  },
  computed: {
    ...mapGetters([
      'visitedViews'
    ])
  },
  watch: {
    $route (route) {
      this.setPageStorage(route)
    },
    visitedViews (newValue, oldValue) {
      this.$utils.sessionStorage.set('tagViews', newValue)
      if (!newValue.some(v => v.fullPath === '/financial-manage/bill-manage')) {
        this.$utils.sessionStorage.remove('billManagePageParams')
      }
      if (!newValue.some(v => v.fullPath === '/financial-manage/cod-manage/cod-collection-rigister')) {
        this.$utils.sessionStorage.remove('codCollectionRigisterPageParams')
      }
      if (!newValue.some(v => v.fullPath === '/operation-center/operation-take-scan')) {
        this.$utils.sessionStorage.remove('tackScanPageParams')
      }
    }
  },
  mounted () {
    const self = this
    window.onresize = function () { // 定义窗口大小变更通知事件
      self.heihgt = '100vh'
      self.width = '100vw'
    }
    window.onbeforeunload = function () { // 刷新
      const n = window.event.screenX - window.screenLeft
      const b = n > document.documentElement.scrollWidth - 20
      if ((b && window.event.clientY < 0) || window.event.altKey) {
        // 关闭
      } else { // 刷新
        if (self.$route.path !== '/login') {
          self.$utils.sessionStorage.set('currentPage', self.routerPath)
          self.$utils.sessionStorage.set('currentPage', self.routerPath)
        }
      }
    }
    this.listeningBack()
  },
  beforeDestroy () { //
    window.removeEventListener('resize', this.resizeMain)
  },
  methods: {
    setPageStorage (route) { // 保存刷新前的页路由
      this.$utils.sessionStorage.set('routerPath', route.fullPath)
      this.$utils.sessionStorage.set('routerQuery', route.query)
      this.$utils.sessionStorage.set('routerParams', route.params)
    },
    listeningBack () { // 监听返回事件跳转路由
      var self = this
      window.onpopstate = function () {
        const routerPath = self.$utils.getUrlRouter()
        const params = self.$utils.getUrlQueryObj()
        const query = self.$utils.getUrlQueryObj()
        if (self.$route.path !== routerPath) { // 当前页面不用跳
          self.$router.push({
            path: routerPath,
            query: query,
            params: params
          })
        }
      }
    }

  }
}
</script>

